package cn.waka.sys.admin.dao.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;

@MappedJdbcTypes({JdbcType.VARCHAR})
@MappedTypes({String.class})
public class UriTypeHandler extends BaseTypeHandler<String> {

  @Override
  public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
    ps.setString(i, parameter);
  }

  @Override
  public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
	String r=rs.getString(columnName);
	if(r!=null&&!r.startsWith("/")){
		r+="/";
	}
    return r;
  }

  @Override
  public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
	  String r=rs.getString(columnIndex);
		if(r!=null&&!r.startsWith("/")){
			r+="/";
		}
    return r;
  }

  @Override
  public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    return cs.getString(columnIndex);
  }
  
 
}
